package drawingtools;


import gui.DrawingPanel;

import java.awt.event.MouseEvent;
import java.util.ArrayList;

import diagramobjects.DiagramObjects;
import diagramobjects.ArrowsTextLine;
import diagramobjects.RealizeLine;
import diagramobjects.Text;

import program.DatabaseConnection;
import utils.Color;
import utils.Point;
import diagramobjects.InheritanceLine;



public class RealizeTool extends DrawingTool {

	
	
	private DiagramObjects DiagramObjs;
	private RealizeLine tempLine;
	private DrawingPanel DrawPanel;
	
	public RealizeTool(DiagramObjects go, DrawingPanel dp)
	{
		DiagramObjs = go;
		DrawPanel = dp;
	}


	@Override
	/**
	 * Reaguje na klikniecie na panelu, 
	 * jesli ClickCount = 0 - poczatek tworzenia
	 * 			dodaje linie do panelu, 
	 * 			odniesienie zapisuje pod tempLine - mozna przesuwac teraz tempLine
	 * 			dodaje tempLine do BD
	 * jesli cliccount == 1
	 * 			zeruje clickcount
	 */
	public void mousePressed(MouseEvent arg0) {
		super.mousePressed(arg0);
		System.out.println("mouseClicked, clickcount:" + ClickCount);
		
		if (ClickCount == 0) 
		{
			DiagramObjs.AddGeometricObjectToPanel(new RealizeLine(0,
																										new Point(arg0.getX(), arg0.getY()),
																										new Point( arg0.getX(), arg0.getY()), 
																										10, 
																										new Text("<<Realize>>", new Point(-10, -10), new Color(0,250,30),10), 
																										false, 
																										true
																									));
			DrawPanel.addSelected();
			tempLine = (RealizeLine)DiagramObjs.GetLastGeometricbjectFromPanel();
			tempLine.Print();
			IncreaseClickCount();
			//DatabaseConnection.AddLine(tempLine.ToDatabase());

		}
		else if (ClickCount == 1)
		{
			ZeroClickCount();
			
		}

	}



	/**
	 * W przypadku rysowania, gdy user przesunie wskaznik myszy przesuwa koniec 
	 * linii i zapisuje jej polozenie w pamieci
	 */
	
	@Override
	public void mouseMoved(MouseEvent e) {
		super.mouseMoved(e);
		if (ClickCount == 1)
		{

			tempLine.MoveEndTo(e.getX(), e.getY(), false, true);
			DrawPanel.repaint();
				
		}

	}
	
}
